package com.bobo.web.provider.config;


import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;



@Configuration
public class ApplicationConfig {

    @Bean(name = "httpComponentsClientHttpRequestFactory")
    public HttpComponentsClientHttpRequestFactory httpComponentsClientHttpRequestFactory() {
        HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
        factory.setConnectTimeout(5000);
        factory.setReadTimeout(3000);
        return factory;
    }

    @Bean(name = "restTemplate")
    public RestTemplateHelper restTemplate(@Qualifier("httpComponentsClientHttpRequestFactory") HttpComponentsClientHttpRequestFactory factory) {
        return new RestTemplateHelper(factory);
    }

    @Bean(name = "fastTimeoutHttpComponentsClientHttpRequestFactory")
    public HttpComponentsClientHttpRequestFactory fastHttpComponentsClientHttpRequestFactory() {
        HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
        factory.setConnectTimeout(5000);
        factory.setReadTimeout(3000);
        return factory;
    }

    @Bean(name = "fastTimeoutRestTemplate")
    public RestTemplateHelper fastTimeoutRestTemplate(@Qualifier("fastTimeoutHttpComponentsClientHttpRequestFactory") HttpComponentsClientHttpRequestFactory factory) {
        return new RestTemplateHelper(factory);
    }



    @Bean
    public ObjectMapper objectMapper() {
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        return objectMapper;
    }


}
